/*************************************************
Author: byron
Date: 11/08/2012
Description:
Notes: 
*************************************************/

#ifndef __CMatrixMgr_h__
#define __CMatrixMgr_h__

#include "../battle/CBattleData.h"

class CMatrixUnit;
class CMatrixList;
class MsgReqMatrix;
class MsgAnsMatrix;
class MsgMatrixList;
class MsgMatrixUnit;
class MsgReqGMPlayer;
class MsgAnsGMPlayer;
class CPlayerBaseInfo;
class CPlayerDetailInfo;
class CPlayerOnlineData;

class CMatrixMgr
{
public:
    enum CMD_MATRIX_SUB_MAP
    {
        CMD_MATRIX_SUB_GET = 1,                 //拉取列表
        CMD_MATRIX_SUB_SET = 2,                 //设置主阵形
        CMD_MATRIX_SUB_ADD = 3,                 //加入个体
        CMD_MATRIX_SUB_DEL = 4,                 //移出个体
        CMD_MATRIX_SUB_SWAP_OBJ = 5,            //交换两个个体
        CMD_MATRIX_SUB_SWAP_ORDER = 6,          //交换两个出手顺序
        CMD_MATRIX_SUB_FIGHTING = 7,            //获取阵型战斗力
    };

    //阵形站位掩码
    enum ENUM_MATRIX_POS_MASK_TAG
    {
        MATRIX_POS_FRONT_MASK_A     = (0x1 << 4),   //前场 从0计算站位4
        MATRIX_POS_FRONT_MASK_B     = (0x1 << 5),   //前场 从0计算站位5
        MATRIX_POS_FRONT_MASK_C     = (0x1 << 6),   //前场 从0计算站位6
        MATRIX_POS_BACK_MASK_D      = (0x1 << 0),   //后场 从0计算站位0
        MATRIX_POS_BACK_MASK_E      = (0x1 << 1),   //后场 从0计算站位1
        MATRIX_POS_BACK_MASK_F      = (0x1 << 2),   //后场 从0计算站位2
    };
    
    //阵形站位下标
    enum ENUM_MATRIX_POS_INDEX_TAG
    {
        MATRIX_POS_FRONT_INDEX_A    = 4,         //前场 从0计算站位4
        MATRIX_POS_FRONT_INDEX_B    = 5,         //前场 从0计算站位5
        MATRIX_POS_FRONT_INDEX_C    = 6,         //前场 从0计算站位6
        MATRIX_POS_BACK_INDEX_D     = 0,         //后场 从0计算站位0
        MATRIX_POS_BACK_INDEX_E     = 1,         //后场 从0计算站位1
        MATRIX_POS_BACK_INDEX_F     = 2,         //后场 从0计算站位2
    };

    //阵形站位序号 前端从后场到前场用1到6表示
    enum ENUM_MATRIX_POS_NUMBER_TAG
    {
        MATRIX_POS_NUMBER_A     = 1,
        MATRIX_POS_NUMBER_B     = 2,
        MATRIX_POS_NUMBER_C     = 3,
        MATRIX_POS_NUMBER_D     = 4,
        MATRIX_POS_NUMBER_E     = 5,
        MATRIX_POS_NUMBER_F     = 6,
    };

    enum ENUM_MATRIX_COUNT_LIMIT_TAG
    {
        MATRIX_COUNT_LIMIT_SWORD    = 2,    //魔剑人数限制
        MATRIX_COUNT_LIMIT_BOW      = 2,    //魔弓人数限制
        MATRIX_COUNT_LIMIT_MAGE     = 2,    //魔法师人数限制
        MATRIX_COUNT_LIMIT_GUARD    = 2,    //魔斗士人数限制
    };

    enum ENUM_MATRIX_LEVEL_LIMIT_TAG
    {
        MATRIX_LEVLE_LIMIT_LVL_A    = 20,    //等级限制段1
        MATRIX_LEVLE_LIMIT_LVL_B    = 30,    //等级限制段2
        MATRIX_LEVLE_LIMIT_NUM_INIT =  3,    //等级段0限制数量
        MATRIX_LEVLE_LIMIT_NUM_A    =  4,    //等级段1限制数量
        MATRIX_LEVLE_LIMIT_NUM_B    =  5,    //等级段2限制数量
    };

    CMatrixMgr()
    {
    }

    virtual ~CMatrixMgr()
    {
    }

    int InitMatrix(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail);

    int GetDefaultIndexAndMask(unsigned char ucCareer, char& chPos,
            unsigned int& uiPosMask);

    int GetPosNumByIndex(char chPos);

    int GetRtoLPosNumByIndex(char chPos);

    char GetIndexByPosNum(int iIndex);

    int PosMaskToIndex(unsigned int uiPosMask, int& iIndex);

    int CheckMatrixObjType(char chObjType);

    int GetUnitIndexByTypeAndID(CMatrixList& stMatrixList, char chType,
            unsigned int uiID);

    int IndexToPosMask(unsigned int& uiPosMask, int iIndex);

    int GetCareerLimit(unsigned char ucCareer, int& iCount);

    int CheckCareerPos(unsigned char ucCareer, char chPos, char chObj);

    int GetMatrixObjNum(CMatrixList& stMatrixList);

    int GetLevelLimit(int iLevel);

    int CheckLevelLimit(int iLevel, int iNum);

    void GetMatrixFighting(CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline, MsgMatrixList& stMsgMatrixList);

    int NotifyMatrix(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline);

    int GetMatrixData(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline, MsgAnsMatrix& stAns);

    bool IsMainMatrix(CPlayerDetailInfo& stPlayerDetail, char chIndex);

    int SetMainMatrix(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline, MsgReqMatrix& stReq,
            MsgAnsMatrix& stAns);

    int CopyMatrixListToAns(CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline, CMatrixList& stMatrixList,
            MsgMatrixList& stMsgMatrixList);

    int CheckObjAddMatrix(CMatrixList& stMatrixList,
            const MsgMatrixUnit& stMatrixUnit, CPlayerBaseInfo& stPlayerBase,
            CPlayerOnlineData& stPlayerOnline, unsigned int& uiPosMask,
            int& iOrder, char& chPos, char& chCareer);

    int AddToMatrix(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline, MsgReqMatrix& stReq,
            MsgAnsMatrix& stAns);

    int DelFromMatrix(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline, MsgReqMatrix& stReq,
            MsgAnsMatrix& stAns, bool bNeedCopyData);

    int GetMatrixCareer(unsigned char& ucCareer, CMatrixUnit& stMatrixUnit);

    int SwapTwoMatrix(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline, MsgReqMatrix& stReq,
            MsgAnsMatrix& stAns);

    int SwapTwoOrder(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline, MsgReqMatrix& stReq,
            MsgAnsMatrix& stAns);

    int DelAllPartner(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline, short shResID);

    bool PartnerInMainMatrix(CPlayerDetailInfo& stPlayerDetail, short shResID);

    void SendMatrixFightingToFront(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline);

    int CalcMainFighting(CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline);

    int ReCalcMainFighting(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline);

    int ReCalcMainObjAttr(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline,
            CPlayerDetailInfoEx1& stPlayerDetailEx1);

    int GetPlayerPosAndOrder(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail, char& chPos, char& chOrder);

    int GetMatrixPos(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail, char chObjType,
            unsigned int uiID);

    int GetMatrixRtoLPos(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail, char chObjType,
            unsigned int uiID);

    int GMDealMatrix(CPlayerDetailInfo& stPlayerDetail, MsgReqGMPlayer& stReq,
            MsgAnsGMPlayer& stAns);

    int CheckValidPos(T_BATTLE_SIDE_DATA& aiMonsterPos);

    int CheckValidOrder(T_BATTLE_SIDE_DATA& aiMonsterOrder);
};

#endif //__CMatrixMgr_h__

